<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
		<script>
			function Obj(value) {
				this.value = value
				this.next = null
			}

			Obj.prototype[Symbol.iterator] = function () {
				var iterator = { next: next }

				var current = this
                // next指向的是遍历器返回的对象
				function next() {
					if (current) {
                        // 获取当前对象的value值
						var value = current.value
                        // 手动把current指向下一个对象
						current = current.next
						return { done: false, value: value }
					}
					return { done: true }
				}
				return iterator
			}

			var one = new Obj(1)
			var two = new Obj(2)
			var three = new Obj(3)

			one.next = two
			two.next = three

			for (var i of one) {
				console.log(i) // 1, 2, 3
			}
		</script>
	</head>
	<body></body>
</html>
